"""
JANVRESSE-MARTIN
"""

import hopfield
from patterns import learning_patterns, test_patterns, pattern_size, np_to_str
from pattern_img import read_image_patterns, write_image_pattern
import multi_hopfield


print("Testing text patterns")
m = hopfield.new_network(pattern_size(learning_patterns))
hopfield.learn(m, learning_patterns)

for pattern in test_patterns:
    print("#" * 20)
    print("IN")
    print("\n".join(np_to_str(pattern)))
    print("#" * 20)
    
    result = hopfield.work(m, pattern)
    
    print("#" * 20)
    print("OUT")
    print("\n".join(np_to_str(result)))
    print("#" * 20)
    
input_images = ["lena.png", "baboon.png", "house.png"]
print("Testing images :", ", ".join(input_images))
#here learnings is an array of 8 elements, one for each pixel
learning_patterns, pattern_shape = read_image_patterns(*input_images)

networks = multi_hopfield.new_network(len(learning_patterns), pattern_shape[0] * pattern_shape[1])
multi_hopfield.learn(networks, learning_patterns)

test_patterns, pattern_shape = read_image_patterns(*["test_" + filename for filename in input_images])

results = multi_hopfield.work(networks, test_patterns)
write_image_pattern(("out_" + filename for filename in input_images), results, pattern_shape)
    
print("Done.")
    
    